package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.CheckApprovalDao;
import cn.topevery.garden.entity.po.CheckApproval;
import cn.topevery.garden.entity.query.CheckApprovalQuery;
import cn.topevery.garden.entity.vo.CheckApprovalVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.CommandType;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import hw.topevery.framework.entity.Value;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 审批
 *
 * @author code-generate
 * @date 2022-02-21
 */
@Repository
public class CheckApprovalDaoImpl extends BaseDaoImpl<CheckApproval> implements CheckApprovalDao {
    @Override
    public <P extends DbCsp> List<CheckApproval> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<CheckApprovalVO> listPage(CheckApprovalQuery query) {
        String table = "t_check_approval tca";

        String columns = "tca.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tca.c_id desc");
        sqlQueryMate
                .where(true, "tca.c_db_status", ScriptConditionEnum.Eq, 0)
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, CheckApprovalVO.class);
    }

    public CheckApproval getInfoApprovalId(String type,String id) {
        Value<CheckApproval> res = new Value<>();
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT * from t_check_approval where c_approval_id ="+id +" and c_type ="+type);
        String sqlText = sb.toString();
        getDbExecute().run(sqlText, CommandType.Text, dbCmd -> {
            res.data = dbCmd.executeToEntity(CheckApproval.class);
        });
        return res.data;

    }

    @Override
    public CheckApproval getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }
}
